package com.dd.stack.jvm.classloader;

/**
 * @Author liuxianmeng
 * @CreateTime 2025/9/12 9:11
 * @Description 类功能作用说明
 */
public class ClassLoaderUse {
    public static void main(String[] args) {
        Class<ClassLoader> classLoaderClass = ClassLoader.class;
        System.out.println("ClassLoader.class = " + classLoaderClass);

        // 获取当前类的类加载器 (通常是 System/App ClassLoader)
        ClassLoader appClassLoader = ClassLoaderUse.class.getClassLoader();
        System.out.println("应用程序类加载器: " + appClassLoader);

        // 获取父加载器 (Platform/Ext ClassLoader)
        ClassLoader extClassLoader = appClassLoader.getParent();
        System.out.println("平台/扩展类加载器: " + extClassLoader);

        // 再获取父加载器 (Bootstrap ClassLoader, 用C++实现，故Java中显示为null)
        ClassLoader bootstrapClassLoader = extClassLoader.getParent();
        System.out.println("启动类加载器: " + bootstrapClassLoader);

        /* ClassLoader.class = class java.lang.ClassLoader
        应用程序类加载器: sun.misc.Launcher$AppClassLoader@18b4aac2
        平台/扩展类加载器: sun.misc.Launcher$ExtClassLoader@5cad8086
        启动类加载器: null */
    }
}
